﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_CommendGood : UCBase 
{
    public UserControls_CommendGood()
    {
        Name = "疯狂抢购";

        swpas = new ShoveWebPartAttribute[6];

        swpas[0] = new ShoveWebPartAttribute_Int("新品图片宽度", "1,400", 110, "新品图片宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("新品图片高度", "1,400", 100, "新品图片高度");
        swpas[2] = new ShoveWebPartAttribute_Int("控件宽度", "1,1000", 546, "控件宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("控件高度", "1,1000", 300, "控件高度");
        swpas[4] = new ShoveWebPartAttribute_Int("控件中每行显示的个数", "1,10", 4, "控件中每行显示产品的个数");

        swpas[5] = new ShoveWebPartAttribute_Int("控件中显示商品总个数", "1,10", 12, "控件中显示商品总个数");

        //swpas[7] = new ShoveWebPartAttribute_Text("商品名CSS样式", "", "pro_name", "商品名CSS样式");
        //swpas[8] = new ShoveWebPartAttribute_Text("市场价CSS样式", "", "market_price", "市场价CSS样式");
        //swpas[9] = new ShoveWebPartAttribute_Text("会员价CSS样式", "", "user_price", "会员价CSS样式");
        //swpas[10] = new ShoveWebPartAttribute_Text("立即节省CSS样式", "", "vip_price", "立即节省CSS样式");
        //swpas[11] = new ShoveWebPartAttribute_Image("新品上架图片", "", "images/UserControls/GoodCommend.bmp", "新品上架图片");
        //swpas[12] = new ShoveWebPartAttribute_Image("新品更多图片", "", "images/UserControls/GoodMore.bmp", "新品更多图片");
        //swpas[13] = new ShoveWebPartAttribute_Color("控件边框颜色", "#cccccc", "控件边框颜色");
    }

    private void Initlayout()
    {
        tabctr.Width = swpAttributes[2];
        tabctr.Height = swpAttributes[3];

        dlCommendGood.RepeatColumns = Shove._Convert.StrToInt(swpAttributes[4], 4);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Initlayout();
        LoadCommendGood();
    }

    /// <summary>
    /// 加载推荐商品
    /// </summary>
    private void LoadCommendGood()
    {
        int Count = Shove._Convert.StrToInt(swpAttributes[5], 12);
        long ShopID = _Site.ID;
        dlCommendGood.DataSource = new DAL.Views.V_Site_GoodShopStock().Open("top " + Count + " *", "isOnSale = 1 and IsCommend = 1", "");
        dlCommendGood.DataBind();
    }

    protected void dlCommendGood_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            try
            {
                Image img = (Image)e.Item.FindControl("imgGoodPic");

                //给商品列添加鼠标事件    
                //img.Attributes.Add("onmouseover", "Over2('" + img.ImageUrl + "')");
                //img.Attributes.Add("onmouseout", "Out2()");

                img.ImageUrl = "~/UpFile/Goods/" + img.ImageUrl;
                img.Width = new Unit(swpAttributes[0]);
                img.Height = new Unit(swpAttributes[1]);
            }
            catch { }
        }
    }

}
